<?php
/**
 * Descript
 * User: blue
 * Date: 2018/8/5 9:29
 */

namespace app\api\validate;


use app\lib\exception\ParamException;
use app\lib\exception\ValidateException;
use think\Validate;

class BaseValidate extends Validate
{

    public static function goCheck($data=[]){
        if(!is_array($data)){
          throw  new ParamException(['message'=>"参数必须为一个数组"]);
        }
        $check=(new self())->check($data);
        if(!$check){
            throw new ValidateException(['message'=>json((new self())->getError())]);
        }
        return true;
    }

    /**
     * 自定义验证规则
     * @param $value
     * @param $rule
     * @param array $data
     */
    protected function isNotEmpty($value,$rule,$data=[]){
        if(empty($value)){
            return false;
        }else{
            return true;
        }
    }
}